package com.zuihai.app.mvp.ui.widget;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;

import com.blankj.utilcode.util.LogUtils;
import com.zuihai.app.mvp.constant.AppConfig;

/**
 * Created by Administrator on 2017/5/19 0019.
 */

public class BigPhotoViewPager extends ViewPager {
    public BigPhotoViewPager(Context context) {
        super(context);
    }

    public BigPhotoViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) {

        float startY =0;
        float endY = 0;

        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:

                startY = event.getY();

                break;
            case MotionEvent.ACTION_MOVE:

                break;
            case MotionEvent.ACTION_UP:
                endY=event.getY();
                break;
        }

        if (Math.abs(startY-endY)> AppConfig.scrollExit){
            mListener.onFinish();
            LogUtils.e("startY : "+startY  +"  "+"endY"+ endY  );

        }
        try {
            return super.onInterceptTouchEvent(event);
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (ArrayIndexOutOfBoundsException e) {
            e.printStackTrace();
        }
        return false;
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {

        return super.onTouchEvent(event);
    }

    private OnViewpagerFinishListener mListener;
    public void setOnFinishClickListenre(OnViewpagerFinishListener listenre) {
        this.mListener = listenre;
    }


    public interface OnViewpagerFinishListener{
        void onFinish();
    }
}
